package com.hd.service.impl;

import com.hd.entity.User;
import com.hd.service.IUserService;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.engine.PageQuery;
import org.beetl.sql.core.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private SQLManager sqlManager;

    @Override
    public PageQuery hi(PageQuery pageQuery) {
        User user = new User();
        user.setAge(10);
        user.setName("nihao");
        user.setUserName("username");
        user.setRoleId(12);
        user.setCreateDate(new Date());
        sqlManager.insert(user);

        Long ct = sqlManager.allCount(User.class);

        System.out.println("总记录数:" + ct);

        Query<User> query = sqlManager.query(User.class);
        List<User> list = query.andBetween("id", 1, 100).select();

        sqlManager.pageQuery("user.queryNewUser", User.class, pageQuery);

        //return "success:"+port+", mills="+mills;
        return pageQuery;
    }

    @Override
    public void saveUser(User user) {
        sqlManager.insert(user);
        //int a = 1/0;
    }
}
